using System;
using Cinemachine;
using Cysharp.Threading.Tasks;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using UnityEngine;
using UnityEngine.Playables;

namespace IQIGame.Onigao.GamePlay
{
    public class CriwareAudioBehaviour : PlayableBehaviour
    {
        public int audioID;

        public static ScriptPlayable<CriwareAudioBehaviour> Create(PlayableGraph graph, GameObject gameObject)
        {
            if (gameObject == null)
                return ScriptPlayable<CriwareAudioBehaviour>.Null;

            var handle = ScriptPlayable<CriwareAudioBehaviour>.Create(graph);
            return handle;
        }

        public override void OnBehaviourPlay(Playable playable, FrameData info)
        { 
            base.OnBehaviourPlay(playable, info);
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                var rConfig = TableCenter.audio.Get(this.audioID);
                SkillEditorMainUpdate.Instance.PlayAudioById(rConfig.Cue,rConfig.Sheet, rConfig.Selector,rConfig.Label);
            }
            else
#endif
            {
                ManagerCenter.Audio.PlayAudioById(this.audioID);
            }
        }
    }
}